<?php

class VInputSelect extends VInput {
	protected $sql;

	public function __construct($nome, $valor='', $label='', $sql='', $tag=''){
		parent::__construct($nome, $valor, $label, $tag);
		$this->sql	= $sql;
	}
	public function __toString(){
		$l	  = ucfirst($this->label) . ":";
		$v	  = $this->valor;
		$n	  = $this->nome;
		$t	  = $this->tag;
		global $cnxIntra;
		$html = "<label>\n" .
				"\t<span>$l</span>\n" .
                "</label>" . 
				"\t<select class=\"input-text\" name=\"$n\">" ;
		// Faz a Consulta
		$queryIntra = new Consulta($cnxIntra, $this->sql);
		foreach($queryIntra->getResultadosNum()as $linha){
			$val   = $linha[0];
			$txt   = $linha[1];
			if($val == $v){
				$html .= "\t<option value=\"$val\" selected>$txt</option>\n";
			} else {
				$html .= "\t<option value=\"$val\">$txt</option>\n";
			}
		}
		$html .= "</select>\n" ;
		return $html;
	}
}
?>